import type { Request, ResponseToolkit } from "@hapi/hapi";
import Hapi from "@hapi/hapi";
import { Notes, User } from "../../model/index";

let route: Hapi.ServerRoute<Hapi.ReqRefDefaults> = {
  path: "/getCurrentNote",
  method: "get",
  handler: async (r: any, h: ResponseToolkit) => {
    try {
      let note = await User.find({ _id: r.userId })
        .select("note")
        .populate({
          path: "note",
          match: {
            status: true,
          },
        });
      //   const note: any = await Notes.find({ pid: r.userId, status: true });
      return { code: 200, data: note };
    } catch (err: any) {
      return err;
    }
  },
  options: {
    plugins: {
      "hapi-swagger": {
        security: [{ apiKey: [] }],
      },
    },
    tags: ["api"],
  },
};
export default route;
